﻿#pragma once

#include <QObject>
#include "TradeDetail.h"
#include "MarketDataBase.h"
#include "StrategyManager.h"
#include <map>
#include "MetricsDataGather.h"

class Trader : public QObject
{
	//Q_OBJECT

public:
	Trader(MetricsDataGather *pGather, QObject *parent = nullptr);
	~Trader();

	// 提前准备
	// 初始化所有合约
	void InitAllSymbols(time_t pCircleEnd);
	// 初始化某个合约
	void InitSymbol(const std::string &pSymbol, time_t pCircleEnd);
	//// 处理价格
	//void OnDealPrice(const std::string &pSymbolName, MData::PriceItem &pItem);
	// 处理行情
	void OnDealMarket(const std::string &pSymbolName, time_t lastNewKTime, const MData::PriceItem &priceItem);
	// 清空初始化数据
	void ClearInitData(const std::string &pSymbol);

	// CTP下单函数
	virtual void InsertCTPOrder(const TD::OrderOption &pOption, TD::OrderBackFunc pFunc) = 0;
protected:
	// 设置交易句柄
	void setTradeHandle(UsrTradeInterface *pHandle) { m_TradeHandle = pHandle; }
	//// 返回账户信息
	//virtual bool getAccountDetail(QryData::Account &outAccount) = 0;
	//// 返回仓位信息
	//virtual bool getPositionDetail(const std::string &pSymbol, QryData::Position &outPos) = 0;
	//// 返回下单信息
	//bool getOrderDetail(const std::string &pSymbol, TD::Order &outOrder);


	UsrTradeInterface *m_TradeHandle;
	MetricsDataGather *m_dataGather; // 数据收集工具
	StrategyManager m_strategyManager;
};
